const app = getApp();
Page({
	data: {
		resourceDomain: app.resourceDomain,
		g_iphone: '',
	},
	onReady: function() {
		app.SystemInfo(this)
	},
	onLoad: function(options) {
        console.log(options.order_no);
        console.log(options.take_user_id);
        
		var that = this;
    app.SystemInfo(that)
		app.request(app.apiDomain + 'index.php?c=user&a=orderdetail',{
			order_no:options.order_no,
			user_id:options.user_id
		}, function(res) {
			console.log(res)
			if (res.data.status == '1') {
				that.setData({
					order: res.data.data,
				});
			}
		});
	},
	copyBtn: function(e) {
        var that = this;
        console.log(e);
		console.log(e._relatedInfo.anchorTargetText)
		wx.setClipboardData({
			//准备复制的数据
			data: e._relatedInfo.anchorTargetText,
			success: function(res) {
				wx.showToast({
					title: '复制成功',
					icon:'none',
					duration: 1000,
				});
			}
		})
	},
	navigator_click() {
		wx.navigateBack({
			changed: true
		});
	},
	step_click() {
		wx.chooseAddress({
			success: (res) => {
				this.setData({
					step: res.provinceName + '-' + res.cityName + '-' + res.countyName + '-' + res.detailInfo,
					name: res.userName,
					phone: res.telNumber
				})
			},
			fail: function(err) {
				console.log(err)
			}
		})
	},
	get_click: function(e) {
		// console.log(e)
		app.request(app.apiDomain + "index.php?c=mall&a=toPay", {
			orderNo: e.target.dataset.id
		}, function(res) {
			var than = res;
			if (res.data.status == 0) {
				wx.showToast({
					title: res.data.info,
					icon: 'none',
					duration: 2000
				})
				return;
			} else if (res.data.status == 1) {
				wx.requestPayment({
					'timeStamp': res.data.data.timeStamp,
					'nonceStr': res.data.data.nonceStr,
					'package': res.data.data.package,
					'signType': res.data.data.signType,
					'paySign': res.data.data.paySign,
					'success': function(res) {},
					'fail': function(res) {
						wx.showToast({
							title: '支付失败',
							icon: 'none',
							duration: 2000
						})
					},
					'complete': function(res) {
						console.log(res)
						if (res.errMsg == "requestPayment:ok") { // 调用支付成功
							wx.redirectTo({
								url: 'list' //
							})
						} else if (res.errMsg == 'requestPayment:cancel') {
							// 用户取消支付的操作
							wx.showToast({
								title: '已取消支付',
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
			}
		});
	},
	onShareAppMessage: function() {
		return app.onShareAppMessage();
	}
})
